var $ = getApp(), methods = require("../methods.js");
Page(Object.assign({}, methods, {
	data: {
		st: 1,
		datalist: [],
		pagenum: 1,
		nodata:1,
		count:0,
		keyword:''
	},
	_onLoad: function (options) {
		var that = this
		wx.setNavigationBarTitle({
			title: (that.data.textset['会员'] || '会员')+'列表'
		});
		var keyword = that.data.keyword
		$.get($.pre_url + '/am.php?s=/member/index', {keyword:keyword}, function (res) {
			if(res.status==0){
				$.alert(res.msg);return;
			}
			that.setData({status:1,count:res.count});
		})
		that.getDataList();
  },
	changetab: function (e) {
		var st = e.currentTarget.dataset.st
		this.setData({ pagenum:1,st: st,datalist:[],$nomoreData:false})
		wx.pageScrollTo({
			scrollTop:0,duration:0
		})
		this.getDataList()
	},
	getDataList: function(){
		var that = this
		var pagenum = that.data.pagenum
		var st = that.data.st
		var keyword = that.data.keyword
		$.post($.pre_url + '/am.php?s=/member/index', {keyword:keyword,st:st,pagenum:pagenum}, function (res) {
			var data = res.data
			if(pagenum == 1){
				console.log(data);
				that.setData({ datalist: data,count:res.count});
				if (data.length == 0){
					that.setData({ nodata:1});
					$.showEmpty('暂无记录','/images/empty2.png');
				}else{
					that.setData({ nodata:0});
				}
			}else{
				if (data.length == 0){
					that.setData({$nomoreData:true});
				}else{
					var datalist = that.data.datalist
					var newdata = datalist.concat(data)
					that.setData({ datalist: newdata });
				}
			}
		});
	},
	onReachBottom: function () {
		if (!this.data.$dataEmpty.visible && !this.data.$nomoreData){
			this.setData({ pagenum: this.data.pagenum+1 })
			this.getDataList();
		}
	},
	searchChange: function (e) {
		this.setData({
			keyword: e.detail.value
		});
	},
	searchConfirm: function (e) {
		var that = this;
		var keyword = e.detail.value;
		that.setData({ keyword: keyword });
		this.setData({ pagenum:1,datalist:[],$nomoreData:false})
		that._onLoad();
	},
}))